package com.jy.adscm.operation.hscrb.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.hscrb.bean.SbwxEquipmentdetail;
import com.jy.adscm.operation.hscrb.mapper.mysql.SbwxEquipmentdetailMapper;
import com.jy.adscm.operation.hscrb.service.SbwxEquipmentdetailService;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2018-12-18
 */
@Service
public class SbwxEquipmentdetailServiceImpl extends ServiceImpl<SbwxEquipmentdetailMapper, SbwxEquipmentdetail> implements SbwxEquipmentdetailService {
    @Autowired
    JyUserMapper jyUserMapper;
    @Override
    public Boolean updateSbwxEquipmentdetail(SbwxEquipmentdetail sbwxEquipmentdetail) {
        boolean result = super.updateById(sbwxEquipmentdetail);
        return result;
    }

    @Override
    public List<SbwxEquipmentdetail> selectByTid(String tid) {
        Wrapper<SbwxEquipmentdetail> wrapper =new EntityWrapper<>();
        wrapper.eq("TID",tid);
        List<SbwxEquipmentdetail> sbwxEquipmentdetails = super.selectList(wrapper);
        for (SbwxEquipmentdetail sbwxEquipmentdetail : sbwxEquipmentdetails) {
            if (AdscmBaseUtils.getInstance().isNotEmpty(sbwxEquipmentdetail.getNeeder(),null) ){
                JyUser jyUser = jyUserMapper.selectById(sbwxEquipmentdetail.getNeeder());
                sbwxEquipmentdetail.setNeederName(jyUser.getName());
            }
            if (AdscmBaseUtils.getInstance().isNotEmpty(sbwxEquipmentdetail.getCustomer(),null) ){
                JyUser jyUser = jyUserMapper.selectById(sbwxEquipmentdetail.getCustomer());
                sbwxEquipmentdetail.setCustomerName(jyUser.getName());
            }
        }
        return sbwxEquipmentdetails;
    }

    @Override
    public List<JyUser> selectUser() {
        Wrapper<JyUser> wrapper =new EntityWrapper<>();
        wrapper.setSqlSelect("id","name");
        List<JyUser> jyUsers = jyUserMapper.selectList(wrapper);
        return jyUsers;
    }
}
